package com.itheima.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class class1 = Class.forName("com.itheima.reflect.Student");
        Constructor[] constructors = class1.getConstructors();
        for (Constructor c : constructors) {
            System.out.println(c);
        }

        System.out.println("-------------------");
        Constructor[] declaredConstructors = class1.getDeclaredConstructors();
        for (Constructor d : declaredConstructors) {
            System.out.println(d);
        }

        System.out.println("--------------------");
        Constructor constructor = class1.getConstructor();
        Constructor constructor1 = class1.getConstructor(String.class, int.class);
        System.out.println(constructor);
        System.out.println(constructor1);

        System.out.println("--------------------");
        Constructor d = class1.getDeclaredConstructor(String.class);
        System.out.println(d);
        d.setAccessible(true);
        Student stu = (Student)(d.newInstance("张三"));
        System.out.println(stu);
        System.out.println("---------------------");

        Class mathClass = Math.class;
        /*Class<?> aClass = Class.forName("java.lang.Math");
        Constructor declaredConstructor = aClass.getDeclaredConstructor();
        declaredConstructor.setAccessible(true);
        Math o =(Math) declaredConstructor.newInstance();*/
        Constructor dec = mathClass.getDeclaredConstructor();
        dec.setAccessible(true);
        Math math = (Math)(dec.newInstance());
        System.out.println(math);
        System.out.println(math.random());
    }
}
